package com.allwees.core.dao.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.core.convert.converter.Converter;

import java.util.ArrayList;
import java.util.List;

public class PageUtil {
    public static Page create(IPage page) {
        return new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
    }

    public static <S, T> IPage<T> convert(IPage<S> page, Converter<S, T> converter) {
    	IPage<T> toPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
    	List<T> result = new ArrayList<>();
    	for(S s : page.getRecords()) {
    		result.add(converter.convert(s));
    	}
    	toPage.setRecords(result);
    	return toPage;
    }
}
